/** COPYRIGHT(C) 2008. Loc Phan. All Rights Reserved.
    A class that receive and check if a date is valid.
    @author Loc Phan
    @version 1.01 2008-10-28
*/
public class DateCheck
{
   /**Constructs a DateCheck object
    * 
    * @param input String contains Date
    */
   public DateCheck(String input)
   {
      date = input;
   }
   /**Check if date is valid
    * 
    * @return True if Date is valid
    */
   public boolean isValidDate()
   {
      boolean answer;
      try
      {
         int day = Integer.parseInt(date.substring(3,5));
         int year = Integer.parseInt(date.substring(6,10));
         int month = Integer.parseInt(date.substring(0,2));
         int days_in_month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
         int days_in_month_leap[] = {31,29,31,30,31,30,31,31,30,31,30,31};
         
         if (isLeapYear(year))
            {
               answer = (day<=days_in_month_leap[month-1]);
            }  
         else
            {
               answer = (day<=days_in_month[month-1]);
            }
      }
      catch(Exception e)
      {
         answer = false;
      }
      return answer; 
   }
   /**Check if year is leap year
    * 
    * @param year Year
    * @return True if input is a leap year
    */
   private boolean isLeapYear(int year)
   {
       return (((year%4==0)&&(year%100!=0))||(year%400==0));
   }
   private String date;
}
